package com.xjcs.saplingplan.view

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.Paint
import android.graphics.PixelFormat
import android.graphics.drawable.Drawable

class TextDrawable : Drawable() {
    private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = Color.RED // 数字背景颜色
        style = Paint.Style.FILL
        textAlign = Paint.Align.CENTER
    }
    
    var text: String = ""
    var textSize: Float = 12f
    var textColor: Int = Color.WHITE
    
    override fun draw(canvas: Canvas) {
        // 绘制圆形背景
        canvas.drawCircle(bounds.width() - 10f, 10f, 10f, paint)
        
        // 绘制文本
        paint.color = textColor
        paint.textSize = textSize
        canvas.drawText(
            text, 
            bounds.width() - 10f, 
            15f, // 垂直居中调整
            paint
        )
    }
    
    // 其他必要方法
    override fun setAlpha(alpha: Int) {}
    override fun setColorFilter(colorFilter: ColorFilter?) {}
    override fun getOpacity() = PixelFormat.TRANSLUCENT
}